# coding:utf-8

import urllib.request


def main():
    # 请求的头部，User-Agent为浏览器的类型
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",

    }

    # 请求的url
    url = 'https://www.xmut.edu.cn'

    # request请求对象，请求某一网站的内容
    request = urllib.request.Request(url, headers=header)

    # 网站的响应
    # response1 = urllib.request.urlopen('https://www.xmut.edu.cn')
    response2 = urllib.request.urlopen(request)

    # 读取响应信息的字节流,这里需要进行utf-8的解码
    html = response2.read().decode('utf-8')
    # 信息写入文件
    f = open('./AL9-7.txt', 'w',encoding='utf-8')

    f.write(html)
    f.close()


if __name__ == "__main__":
    main()
